/*
 * Object.cpp
 *
 *  Created on: Aug 26, 2011
 *      Author: mengwei.chua
 */

#include "Object.h"
#include "ParserHelper.h"

namespace projectcos
{
namespace tile
{
namespace parser
{

Object::Object()
: m_Name("")
, m_Type("")
, m_X(0)
, m_Y(0)
, m_Width(0)
, m_Height(0)
, m_GID(0)
{
	m_ImageList.clear();
}

Object::~Object()
{
	m_ImageList.clear();
}

bool Object::Parse(const TiXmlElement* element)
{
	// Parse attributes
	TIXML_QUERY_STRING(element, "name", m_Name);
	TIXML_QUERY_STRING(element, "type", m_Type);
	TIXML_QUERY_UNSIGNED_INT(element, "x", m_X);
	TIXML_QUERY_UNSIGNED_INT(element, "y", m_Y);
	TIXML_QUERY_UNSIGNED_INT(element, "width", m_Width);
	TIXML_QUERY_UNSIGNED_INT(element, "height", m_Height);
	TIXML_QUERY_UNSIGNED_INT(element, "gid", m_GID);

	// Parse child elements
	const TiXmlElement* child = element->FirstChildElement("properties");
	if(NULL != child)
	{
		m_Properties.Parse(child);
	}

	child = element->FirstChildElement("image");
	while(NULL != child)
	{
		Image image;
		if(image.Parse(child))
		{
			m_ImageList.push_back(image);
		}

		child = child->NextSiblingElement("image");
	}

	return true;
}

std::string Object::GetName() const
{
	return m_Name;
}

std::string Object::GetType() const
{
	return m_Type;
}

unsigned int Object::GetX() const
{
	return m_X;
}

unsigned int Object::GetY() const
{
	return m_Y;
}

unsigned int Object::GetWidth() const
{
	return m_Width;
}

unsigned int Object::GetHeight() const
{
	return m_Height;
}

unsigned int Object::GetGID() const
{
	return m_GID;
}

void Object::GetProperties(Properties& properties) const
{
	properties = m_Properties;
}

void Object::GetImages(std::deque<Image>& images) const
{
	images = m_ImageList;
}

} // parser
} // tile
} // projectcos
